package com.teen9g.infoplatformserver.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.teen9g.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    /**
     * 获取全部用户信息
     *
     * @return
     */
    List<User> getUser();

    @Select("SELECT avatar_url FROM user WHERE id = #{receiverId}")
    String getAvatarUrlByUserId(@Param("receiverId") Integer receiverId);

    @Update("update user set avatar_url = #{avatar} where id = #{id}")
    void updateAvatarUrlByUserId(@Param("id") Integer id, @Param("avatar") String avatar);

    @Update("update user set fans_count = fans_count + 1 where id = #{followsId}")
    void increaseFans(@Param("followsId") Integer followsId);

    @Update("update user set follows_count = follows_count + 1 where id = #{fansId}")
    void increaseFollows(@Param("fansId") Integer fansId);

    @Select("select signature from user where id = #{fansId}")
    String getSignatureByUserId(@Param("fansId") Integer fansId);

    @Select("select id from user where username = #{shopAuthor}")
    Long getUserIdByUsername(@Param("shopAuthor") String shopAuthor);
}
